//
//  IProduct.m
//  XRmenu
//
//  Created by yangxh on 11-3-24.
//  Copyright 2011 E0571. All rights reserved.
//

#import "IProduct.h"


@implementation IProduct

@synthesize capacity;
@synthesize checkInTime;
@synthesize color;
@synthesize commentNum;
@synthesize entityId;
@synthesize Id;
@synthesize isRecommend;
@synthesize position;
@synthesize productId;
@synthesize productNo;
@synthesize salePrice;
@synthesize scoreCount;
@synthesize status;
@synthesize type;
@synthesize unit;
@synthesize name;
@synthesize spellCode;

//=========================================================== 
// - (id)init
//
//=========================================================== 
- (id)init
{
	return [self initWithCapacity:nil checkInTime:nil color:0 commentNum:0 entityId:nil Id:0 isRecommend:NO position:nil productId:nil productNo:nil salePrice:nil scoreCount:nil status:0 type:0 unit:nil];
}


//=========================================================== 
// - (id)initWith:
//
//=========================================================== 
- (id)initWithCapacity:(NSString*)aCapacity checkInTime:(NSDate*)aCheckInTime color:(NSInteger)aColor commentNum:(NSInteger)aCommentNum entityId:(NSString*)anEntityId Id:(NSInteger)anId isRecommend:(BOOL)flag position:(NSString*)aPosition productId:(NSString*)aProductId productNo:(NSString*)aProductNo salePrice:(NSNumber*)aSalePrice scoreCount:(NSNumber*)aScoreCount status:(NSInteger)aStatus type:(NSInteger)aType unit:(NSString*)anUnit 
{
    self = [super init];
    if (self) {
        self.capacity = aCapacity;
        self.checkInTime = aCheckInTime;
        self.color = aColor;
        self.commentNum = aCommentNum;
        self.entityId = anEntityId;
        self.Id = anId;
        self.isRecommend = flag;
        self.position = aPosition;
        self.productId = aProductId;
        self.productNo = aProductNo;
        self.salePrice = aSalePrice;
        self.scoreCount = aScoreCount;
        self.status = aStatus;
        self.type = aType;
        self.unit = anUnit;
    }
    return self;
}


//=========================================================== 
// + (id)objectWith:
//
//=========================================================== 
+ (id)objectWithCapacity:(NSString*)aCapacity checkInTime:(NSDate*)aCheckInTime color:(NSInteger)aColor commentNum:(NSInteger)aCommentNum entityId:(NSString*)anEntityId Id:(NSInteger)anId isRecommend:(BOOL)flag position:(NSString*)aPosition productId:(NSString*)aProductId productNo:(NSString*)aProductNo salePrice:(NSNumber*)aSalePrice scoreCount:(NSNumber*)aScoreCount status:(NSInteger)aStatus type:(NSInteger)aType unit:(NSString*)anUnit  
{
    id result = [[[self class] alloc] initWithCapacity:aCapacity checkInTime:aCheckInTime color:aColor commentNum:aCommentNum entityId:anEntityId Id:anId isRecommend:flag position:aPosition productId:aProductId productNo:aProductNo salePrice:aSalePrice scoreCount:aScoreCount status:aStatus type:aType unit:anUnit];
	
    return [result autorelease];
}

//=========================================================== 
// - (NSArray *)keyPaths
//
//=========================================================== 
- (NSArray *)keyPaths
{
    NSArray *result = [NSArray arrayWithObjects:
					   @"capacity",
					   @"checkInTime",
					   @"color",
					   @"commentNum",
					   @"entityId",
					   @"Id",
					   @"isRecommend",
					   @"position",
					   @"productId",
					   @"productNo",
					   @"salePrice",
					   @"scoreCount",
					   @"status",
					   @"type",
					   @"unit",
					   @"name",
					   @"spellCode",
					   nil];
	
    return result;
}


//=========================================================== 
// - (NSString *)descriptionForKeyPaths
//
//=========================================================== 
- (NSString *)descriptionForKeyPaths 
{
    NSMutableString *desc = [NSMutableString string];
    NSEnumerator *e = [[self keyPaths] objectEnumerator];
    NSString *thisKey;
    [desc appendString:@"\n\n"];
	
    while ((thisKey = [e nextObject])) {
        [desc appendFormat: @"%@: %@\n", thisKey, [self valueForKey:thisKey]];
    }
	
    return [NSString stringWithString:desc];
}

- (NSString *)description
{
	return [self descriptionForKeyPaths];
}

//=========================================================== 
// dealloc
//=========================================================== 
- (void)dealloc
{
    [capacity release];
    capacity = nil;
    [checkInTime release];
    checkInTime = nil;
    [entityId release];
    entityId = nil;
    [position release];
    position = nil;
    [productId release];
    productId = nil;
    [productNo release];
    productNo = nil;
    [salePrice release];
    salePrice = nil;
    [scoreCount release];
    scoreCount = nil;
    [unit release];
    unit = nil;
	[name release];
	name = nil;
	[spellCode release];
	spellCode = nil;
	
    [super dealloc];
}


+ (IProduct *)iProductByParse:(NSDictionary *)info
{
	IProduct *p = [IProduct objectWithCapacity:dictObject(info,@"Capacity")
								   checkInTime:[NSDate date]
										 color:dictInt(info,@"Color")
									commentNum:dictInt(info,@"CommentNum")
									  entityId:dictObject(info,@"EntityId")
											Id:dictInt(info,@"ID")
								   isRecommend:[dictObject(info,@"IsRecommend") boolValue]
									  position:dictObject(info,@"Position")
									 productId:dictObject(info,@"ProductId")
									 productNo:dictObject(info,@"ProductNo")
									 salePrice:[NSNumber numberWithFloat:[[info objectForKey:@"SalePrice"] floatValue]]
									scoreCount:[NSNumber numberWithFloat:[[info objectForKey:@"ScoreCount"] floatValue]]
										status:dictInt(info,@"Status")
										  type:dictInt(info,@"Type")
										  unit:dictObject(info,@"Unit")];
	p.spellCode = dictObject(info,@"SpellCode");
	return p;
}

@end
